<template>
  <div>
    <ul class="list fx">
      <li class="item bw fx cs">
        <div class="left fx">
          <i class="font1 el-icon-coordinate"></i>
        </div>
        <div class="right">
          班级总数:
          <p>{{ indexInfo.totalClass }}</p>
        </div>
      </li>
      <li class="item bw fx cs">
        <div class="left fx">
          <i class="font2 el-icon-user"></i>
        </div>
        <div class="right">
          总人数:
          <p>{{ count }}</p>
        </div>
      </li>
      <li class="item bw fx cs">
        <div class="left fx">
          <i class="font3 el-icon-tickets"></i>
        </div>
        <div class="right">
          试卷总数:
          <p>{{ paperCount }}</p>
        </div>
      </li>
      <li class="item bw fx cs">
        <div class="left fx">
          <i class="font4 el-icon-edit-outline"></i>
        </div>
        <div class="right">
          题目总数:
          <p>{{ indexInfo.subjects }}</p>
        </div>
      </li>
    </ul>
    <div class="p fx bw">
      <div class="l bw">
        <h2>班级人数分布</h2>
        <ECycleOption
          :o="{
            name: '人数',
            data: indexInfo.classInfo,
          }"
        />
      </div>
      <div class="l bw">
        <h2>班级试卷分布</h2>
        <ECycleOption
          :o="{
            name: 'fad',
            data: indexInfo.paperInfo,
          }"
        />
      </div>
    </div>
  </div>
</template>

<script>
import ECycleOption from "@/components/echart/Tch";
import { getTchInfo } from "@/api/class";
import { formatIndexInfo } from "@/utils";
import { mapState } from "vuex";
export default {
  components: {
    ECycleOption,
  },
  data() {
    return {
      indexInfo: {
        classInfo: [],
        paperInfo: [],
        subjects: 0,
        totalClass: 0,
      },
      paperCount: 0,
    };
  },
  computed: {
    ...mapState(["info"]),
    // 总人数
    count() {
      return this.indexInfo.classInfo.reduce((total, info) => {
        total += info.value;
        return total;
      }, 0);
    },
  },
  async created() {
    const info = await getTchInfo();
    this.paperCount = info.data.paperInfo.length;
    console.log(info.data.classInfo)
    this.indexInfo = formatIndexInfo(info.data);
  },
};
</script>

<style lang="scss" scoped>
.list {
  justify-content: space-between;
}

.item {
  padding: 20px;
  flex-grow: 1;
  margin-right: 10px;
  justify-content: space-between;
  .left {
    margin-right: 30px;
  }
  .right {
    p {
      font-size: 20px;
      font-weight: bold;
      margin-top: 20px;
    }
  }
}

.font1 {
  font-size: 60px;
  color: #40c9c6;
}
.font2 {
  font-size: 60px;
  color: #409eff;
}
.font3 {
  font-size: 60px;
  color: #34bfa3;
}
.font4 {
  font-size: 60px;
  color: #f4516c;
}

.p {
  margin-top: 20px;
  height: 500px;
  align-items: center;
  justify-content: space-between;
}

.l,
.r {
  width: 500px;
  margin-right: 5px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  h2 {
    font-size: 20px;
    font-weight: bold;
  }
}
</style>
